﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace AutoTweet.Utilities
{
    public class Logger
    {
        public static void Log(string module, string error)
        {
            string appPath = AppDomain.CurrentDomain.BaseDirectory;
            if (!appPath.EndsWith(@"\"))
                appPath += @"\";

            string logFile = appPath + string.Format("error_log_{0}.txt", DateTime.Now.ToString("yyyy-MM-dd"));

            try
            {
                FileStream fs = new FileStream(logFile, FileMode.Append);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(string.Format("Module: {0}", module));
                sw.WriteLine(string.Format("{0:dd/MM/yyyy hh:mm:tt}", DateTime.Now));
                sw.WriteLine(error);
                sw.WriteLine("\n");

                sw.Close();
                sw.Dispose();

                fs.Close();
                fs.Dispose();
            }
            catch (Exception ex) { }
        }

        public static void Log(string module, Exception ex)
        {
            Log(module, ex.Message);
        }
    }
}
